﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Data;
using OpenSIS.OpenSISWCFServiceReference;
using System.Globalization;
using OpenSISInstall;
using OSISToolTip;

namespace OpenSIS.School
{
    public partial class PortalNotes : System.Web.UI.Page
    {
        protected string sCulture;
        protected void Page_Load(object sender, EventArgs e)
        {



            Page.RegisterStartupScript("Information", "<Script Language='JavaScript'>  generate_wysiwyg('ctl00_ContentPlaceHolder1_txtNoteEditor');</Script>");

           // OpenSISWCFServicePortalNotesClient PortalNotes = new OpenSISWCFServicePortalNotesClient();
           SISInstall SISInstall = new SISInstall();
           // SchoolBL schoolAdd = new SchoolBL();
            OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
            if (!IsPostBack)
            {
              
                DataTable dtDateFormat = InstallBL.getdateformat();
                if (dtDateFormat.Rows.Count > 0)
                {
                    SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                }
                sCulture = "en-US";
                //OnClientDateSelectionChanged="checkEndDate"
                hdns.Value = sCulture;
                //CalExtEndDate.OnClientDateSelectionChanged = "checkEndDate";
                CalExtStartDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
                CalExtEndDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
                CalExtStartDateEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
                CalExtEndDateEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
                imgBtnEdit.Attributes.Add("onclick", "return GridCheckBoxSelection('" + sCulture + "')");

                TooltipLang TTL = new TooltipLang();
                if (Session["MLCulture"] != null && Session["MLUICulture"] != null)
                {
                    
                    TTL.tooltip();

                    ibtnAdd.Attributes.Add("onmouseover", "toolTip('" + TTL.Add + "')");
                    ibtnAdd.Attributes.Add("onmouseout", "toolTip()");
                    imgBtnEdit.Attributes.Add("onmouseover", "toolTip('" + TTL.Edit + "')");
                    imgBtnEdit.Attributes.Add("onmouseout", "toolTip()");
                    imgBtnDelete.Attributes.Add("onmouseover", "toolTip('" + TTL.Delete + "')");
                    imgBtnDelete.Attributes.Add("onmouseout", "toolTip()");
                    //ibtnAdd.Attributes.Add("onmouseover", "toolTip('Add')");
                    //ibtnAdd.Attributes.Add("onmouseout", "toolTip()");
                    //imgBtnEdit.Attributes.Add("onmouseover", "toolTip('Edit')");
                    //imgBtnEdit.Attributes.Add("onmouseout", "toolTip()");
                    //imgBtnDelete.Attributes.Add("onmouseover", "toolTip('Delete')");
                    //imgBtnDelete.Attributes.Add("onmouseout", "toolTip()");
                }

               btnSave.Attributes.Add("onclick", "return Validation('ctl00_ContentPlaceHolder1_txtTitle','ctl00_ContentPlaceHolder1_txtNoteEditor','ctl00_ContentPlaceHolder1_txtVisibleStartDate','ctl00_ContentPlaceHolder1_txtVisibleEndDate','ctl00_ContentPlaceHolder1_lblMessage','" + sCulture + "')");

                try
                {
                   PopulateStaffTypecheckbox(ref chkVisibleUser);
                    //schoolAdd.MaxSchoolID();
                    //ddlSchoolName.Items.FindByValue(schoolAdd.SchoolID.ToString()).Selected = true;
                    //if (Session["SchoolID"] != null)
                    //{
                    //    ddlSchoolName.Items.FindByValue(Session["SchoolID"].ToString()).Selected = true;
                    //}
                  //  PopulateMasterDropdownFullYear();
                    PopulatePortalNotesGrid();
                }
                catch
                {

                }
                finally
                {

                    InstallBL.Close();
                   // schoolAdd = null;
                }

            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            DataTable dtsortorder = new DataTable();
            OpenSISWCFServicePortalNotesClient PortalNotesadd = new OpenSISWCFServicePortalNotesClient();
            try
            {
               // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
               // PortalNotesadd.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                string Title = txtTitle.Text.ToString().Trim();

                string Notes = Server.HtmlEncode(hdnNoteEditor.Value.ToString());
                string Visiblestartdate = txtVisibleStartDate.Text.ToString();
                string Visibleenddate = txtVisibleEndDate.Text.ToString();


                string strvisibleto = "";
                foreach (ListItem cBox in chkVisibleUser.Items)
                {
                    if (cBox.Selected)
                    {
                        strvisibleto += cBox.Value + " , ";
                    }
                }

                string Visiblestaffid = strvisibleto;
                PortalNotesadd.PortalNotesadd(SchoolID,Title,Notes,Visiblestartdate,Visibleenddate,Visiblestaffid);
                ResetFormControlValues(this.Page);
                chkVisibleUser.SelectedIndex = -1;

                ModalPopupExtenderSave.Enabled = false;
                ModalPopupExtenderSave.Hide();
                PopulatePortalNotesGrid();
            }
            catch
            {

            }
            finally
            {
                PortalNotesadd.Close();
            }

        }

        protected void PopulatePortalNotesGrid()
        {
            OpenSISWCFServicePortalNotesClient PortalNotesview = new OpenSISWCFServicePortalNotesClient();
            DataTable dtportalnotes = null;


            try
            {
              //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
               // PortalNotesview.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);

                //the below code is added to fetch in english format for arabic culture

                //if (Page.Culture == "Arabic (Saudi Arabia)")
                //{
                //    Page.Culture = "en-US";
                //    Page.UICulture = "en";
                //    dtportalnotes = PortalNotesview.PopulatePortalNotes();


                //    Page.Culture = (String)Session["MLCulture"];
                //    Page.UICulture = (String)Session["MLUICulture"];

                //}

                //else
                //{
                // dtportalnotes = PortalNotesview.PopulatePortalNotes();

                // }



                dtportalnotes = PortalNotesview.PopulatePortalNotes(SchoolID);
                string Culture = System.Web.HttpContext.Current.Session["MLCulture"].ToString();
                PortalNotesview.Close();

                if (dtportalnotes.Rows.Count > 0)
                {
                    rlPortalNotes.DataSource = dtportalnotes;
                    rlPortalNotes.DataBind();


                    //********************************6th August****************************
                    //lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Portal Notes were found";




                    switch (Culture)
                    {
                        case "en-US":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Portal Notes were found";
                            break;
                        case "es-MX":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Portal de Notas se encontraron encontrado";
                            break;
                        case "zh-CN":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "门户笔记被发现";
                            break;
                        case "ja-JP":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "ポータルのノートが発見された";
                            break;
                        case "de-DE":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Portal Hinweise gefunden";
                            break;
                        case "ko-KR":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "포탈 노트를 발견했다";
                            break;
                        case "fr-FR":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Portail des notes ont été trouvés";
                            break;
                        case "it-IT":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "portale Note sono stati trovati";
                            break;
                        case "ru-RU":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Портал отмечает, были обнаружены";
                            break;
                        case "pt-BR":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "Portal Notas foram encontrado";
                            break;
                        case "ar-SA":
                            lblFoundCount.Text = rlPortalNotes.Items.Count.ToString() + " " + "تم العثور على بوابة الحواشي";
                            break;
                    }

                    //********************************6th August****************************
                }
                else
                {


                    rlPortalNotes.DataBind();

                    //********************************6th August****************************
                    //lblFoundCount.Text = "No Portal Notes were found";
                    switch (Culture)
                    {
                        case "en-US":
                            lblFoundCount.Text = "No Portal Notes were found";
                            break;
                        case "es-MX":
                            lblFoundCount.Text = "Portal de Notas no se encontraron";
                            break;
                        case "zh-CN":
                            lblFoundCount.Text = "没有门户债券被发现";
                            break;
                        case "ja-JP":
                            lblFoundCount.Text = "いいえポータルなった設立する";
                            break;
                        case "de-DE":
                            lblFoundCount.Text = "Nein Portal Stellt fest waren gefunden";
                            break;
                        case "ko-KR":
                            lblFoundCount.Text = "아니 포탈 노트를 발견했다 ";
                            break;
                        case "fr-FR":
                            lblFoundCount.Text = "Pas de Portal Notes ont été trouvés";
                            break;
                        case "it-IT":
                            lblFoundCount.Text = "No Portale Note sono stati trovati ";
                            break;
                        case "ru-RU":
                            lblFoundCount.Text = "Нет Портал отмечает, были обнаружены";
                            break;
                        case "pt-BR":
                            lblFoundCount.Text = "Não Portal Notas Foram encontrados";
                            break;
                        case "ar-SA":
                            lblFoundCount.Text = "ولم يلاحظ وعثر على البوابة";
                            break;
                    }
                    //********************************6th August****************************
                }
            }
            catch
            {

            }

            finally
            {
               // PortalNotesview.Close();
            }

        }



        //protected void ddlSchoolName_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //SchoolBL schoolAdd = new SchoolBL();
        //    ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //    Session["SchoolID"] = ddlSchoolName.SelectedItem.Value;
        //    PopulatePortalNotesGrid();
        //    PopulateMasterDropdownFullYear();

        //}



        private void ResetFormControlValues(Control parent)
        {

            foreach (Control c in parent.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    ResetFormControlValues(c);
                }
                else
                {
                    switch (c.GetType().ToString())
                    {
                        case "System.Web.UI.WebControls.TextBox":
                            ((TextBox)c).Text = "";
                            break;
                        case "System.Web.UI.WebControls.CheckBox":

                            ((CheckBox)c).Checked = false;
                            break;
                        case "System.Web.UI.WebControls.RadioButton":
                            ((RadioButton)c).Checked = false;
                            break;
                        case "System.Web.UI.WebControls.DropDownList":
                            if (c.ID == "ddlSchoolName" || c.ID == "ddlFullYear" || c.ID == "ddlLevel1")
                            {
                            }
                            else
                            {
                                ((DropDownList)c).SelectedIndex = -1;
                            }
                            break;
                        case "System.Web.UI.WebControls.ListBox":
                            ((ListBox)c).SelectedValue = "0";
                            break;

                        case "System.Web.UI.WebControls.CheckBoxList":

                            foreach (ListItem li in chkVisibleUser.Items)
                            {
                                li.Selected = false;
                            }

                            break;
                    }
                }
            }
        }








        protected void imgBtnDelete_Click(object sender, ImageClickEventArgs e)
        {
            OpenSISWCFServicePortalNotesClient PortalNotesdel = new OpenSISWCFServicePortalNotesClient();
            try
            {
                for (int i = 0; i < rlPortalNotes.Items.Count; i++)
                {
                    CheckBox chkrow = (CheckBox)rlPortalNotes.Items[i].FindControl("chkrow");
                    HiddenField hdnPortalNotesID = (HiddenField)rlPortalNotes.Items[i].FindControl("hdnPortalNotesID");
                    if (chkrow.Checked)
                    {

                       int PortalNotesid = Convert.ToInt32(hdnPortalNotesID.Value);
                        PortalNotesdel.DeletePortalNotes(PortalNotesid);
                        PopulatePortalNotesGrid();
                    }
                }
            }
            catch
            {

            }

            finally
            {
                PortalNotesdel.Close();
            }

        }

        protected void imgBtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            OpenSISWCFServicePortalNotesClient PortalNotes = new OpenSISWCFServicePortalNotesClient();
            try
            {
                foreach (ReorderListItem RI in rlPortalNotes.Items)
                {

                    if (RI.ItemType == ListItemType.Item || RI.ItemType == ListItemType.AlternatingItem)
                    {
                        CheckBox chk = (CheckBox)RI.FindControl("chkrow");
                        if (chk.Checked == true)
                        {
                            HiddenField hdnPortalNotesID = (HiddenField)RI.FindControl("hdnPortalNotesID");
                            HiddenField hdnVisibleStaffId = (HiddenField)RI.FindControl("hdnVisibleStaffId");
                            Label lblTitle = (Label)RI.FindControl("lblTitle");
                            Label lblNotes = (Label)RI.FindControl("lblNotes");
                            Label lblVisibleStartDate = (Label)RI.FindControl("lblVisibleStartDate");
                            Label lblVisibleEndDate = (Label)RI.FindControl("lblVisibleEndDate");
                            hdnportalnoteid.Value = hdnPortalNotesID.Value;
                            txtTitleEdit.Text = lblTitle.Text;
                            txtNoteEditorEdit.Text = lblNotes.Text;
                            txtVisibleStartDateEdit.Text = lblVisibleStartDate.Text;
                            txtVisibleEndDateEdit.Text = lblVisibleEndDate.Text;

                            PopulateStaffTypecheckbox(ref chkVisibleUserEdit);

                            string id = hdnVisibleStaffId.Value.ToString();
                            string[] b = id.Split(new char[] { ',' });

                            for (int k = 0; k < b.Length; k++)
                            {
                                foreach (ListItem itm in chkVisibleUserEdit.Items)
                                {
                                    if (itm.Value.ToLower() == b[k].Trim().ToLower())
                                    {
                                        itm.Selected = true;
                                    }
                                }
                            }


                            ModalPopupExtenderEdit.Enabled = true;
                            ModalPopupExtenderEdit.Show();
                        }
                    }
                }



            }
            catch
            {
            }
            finally
            {
                PortalNotes.Close();
            }
        }


        protected void rlPortalNotes_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)
        {


            DataTable dt = new DataTable();

            OpenSISWCFServicePortalNotesClient PortalNotesview = new OpenSISWCFServicePortalNotesClient();
            try
            {
                if (e.Item.ItemType == ListItemType.Item)
                {
                   // ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");

                   // PortalNotesview.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                    int SchoolID = Convert.ToInt32(Session["SchoolID"]);

                    dt = PortalNotesview.PopulatePortalNotes(SchoolID);

                    if (dt != null)
                    {


                        string strTempOrder = dt.Rows[e.OldIndex]["short_order"].ToString();
                        dt.Rows[e.OldIndex]["short_order"] = dt.Rows[e.NewIndex]["short_order"];
                        dt.Rows[e.NewIndex]["short_order"] = strTempOrder;
                        dt.AcceptChanges();


                        //PortalNotesview.PortalNotesid = Convert.ToInt32(dt.Rows[e.NewIndex]["portal_note_id"].ToString());
                        //PortalNotesview.Sortorder = dt.Rows[e.NewIndex]["Short_Order"].ToString();
                        //PortalNotesview.UpdateShortOrder();
                        int PortalNotesid = Convert.ToInt32(dt.Rows[e.NewIndex]["portal_note_id"].ToString());
                        string Sortorder = dt.Rows[e.NewIndex]["Short_Order"].ToString();
                        PortalNotesview.UpdateShortOrderportalNotes(Sortorder,PortalNotesid);

                        //PortalNotesview.PortalNotesid = Convert.ToInt32(dt.Rows[e.OldIndex]["portal_note_id"].ToString());
                        //PortalNotesview.Sortorder = dt.Rows[e.OldIndex]["Short_Order"].ToString();
                        //PortalNotesview.UpdateShortOrder();

                         PortalNotesid = Convert.ToInt32(dt.Rows[e.OldIndex]["portal_note_id"].ToString());
                         Sortorder = dt.Rows[e.OldIndex]["Short_Order"].ToString();
                        PortalNotesview.UpdateShortOrderportalNotes(Sortorder,PortalNotesid);

                        Sortorder = null;

                        rlPortalNotes.DataSource = PortalNotesview.PopulatePortalNotes(SchoolID); 
                        rlPortalNotes.DataBind();
                    }
                }
            }
            catch
            {
            }
            finally
            {
                PortalNotesview.Close(); 
            }
        }

        //protected void rlPortalNotes_DragAndDrop(object sender, UtilityGrid.OnDragAndDropEventArgs e)
        //{
        //    DataTable dt = new DataTable();

        //    PortalNotesBL PortalNotesview = new PortalNotesBL();
        //    try
        //    {
        //        ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");

        //        PortalNotesview.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);

        //        dt = PortalNotesview.PopulatePortalNotes();

        //        if (dt != null)
        //        {


        //            string strTempOrder = dt.Rows[e.StartIndex]["short_order"].ToString();
        //            dt.Rows[e.StartIndex]["short_order"] = dt.Rows[e.EndIndex]["short_order"];
        //            dt.Rows[e.EndIndex]["short_order"] = strTempOrder;
        //            dt.AcceptChanges();


        //            PortalNotesview.PortalNotesid = Convert.ToInt32(dt.Rows[e.EndIndex]["portal_note_id"].ToString());
        //            PortalNotesview.Sortorder = dt.Rows[e.EndIndex]["Short_Order"].ToString();
        //            PortalNotesview.UpdateShortOrder();

        //            PortalNotesview.PortalNotesid = Convert.ToInt32(dt.Rows[e.StartIndex]["portal_note_id"].ToString());
        //            PortalNotesview.Sortorder = dt.Rows[e.StartIndex]["Short_Order"].ToString();
        //            PortalNotesview.UpdateShortOrder();

        //            PortalNotesview.Sortorder = null;

        //            rlPortalNotes.DataSource = PortalNotesview.PopulatePortalNotes(); ;
        //            rlPortalNotes.DataBind();
        //        }
        //    }
        //    catch
        //    {
        //    }
        //    finally
        //    {
        //        PortalNotesview = null;
        //    }


        //}

        protected void rlPortalNotes_ItemDataBound(object sender, ReorderListItemEventArgs e)
        {
            OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
            SISInstall SISInstall = new SISInstall();
            OpenSISWCFServicePortalNotesClient PortalNotes = new OpenSISWCFServicePortalNotesClient();

            try
            {
                //if (e.Item == DataControlRowType.DataRow)
                //{

                DataTable dtDateFormat = InstallBL.getdateformat();
                if (dtDateFormat.Rows.Count > 0)
                {
                    SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                }


                CheckBoxList chkVisibleStaffID = (CheckBoxList)e.Item.FindControl("chkVisibleStaffID");

                HiddenField hdnPortalNotesID = (HiddenField)e.Item.FindControl("hdnPortalNotesID");
                HiddenField hdnVisibleStaffId = (HiddenField)e.Item.FindControl("hdnVisibleStaffId");
                Label lblNotes = (Label)e.Item.FindControl("lblNotes");

                Label lblVisibleStartDate = (Label)e.Item.FindControl("lblVisibleStartDate");
                Label lblVisibleEndDate = (Label)e.Item.FindControl("lblVisibleEndDate");

                DateTime VisStrtDate = Convert.ToDateTime(lblVisibleStartDate.Text.ToString());
                DateTime VisEndDate = Convert.ToDateTime(lblVisibleEndDate.Text.ToString());

                lblVisibleStartDate.Text = VisStrtDate.ToString(SISInstall.CalenderDateFormat);
                lblVisibleEndDate.Text = VisEndDate.ToString(SISInstall.CalenderDateFormat);



                PopulateStaffTypecheckbox(ref chkVisibleStaffID);

                string id = hdnVisibleStaffId.Value.ToString();
                string[] b = id.Split(new char[] { ',' });

                string strvisibleto = "";
                for (int k = 0; k < b.Length; k++)
                {
                    if (b[k].Trim().ToLower() == "")
                    {
                        strvisibleto += "0";
                    }
                    else
                    {
                        strvisibleto += b[k] + ",";
                    }

                }

                string Visiblestaffid = strvisibleto;
                PopulateSelectedStaffTypecheckbox(ref chkVisibleStaffID,Visiblestaffid);

                foreach (ListItem itm in chkVisibleStaffID.Items)
                {
                    itm.Selected = true;
                }

                using (System.IO.StringWriter stringWriter = new System.IO.StringWriter(new System.Text.StringBuilder()))
                {
                    //Server.HtmlDecode(DataBinder.Eval(e.Row.DataItem, "Note").ToString(), stringWriter);
                    Server.HtmlDecode(DataBinder.Eval(e.Item.DataItem, "Note").ToString(), stringWriter);

                    lblNotes.Text = stringWriter.ToString();
                }
                //}
            }
            catch
            {
            }

            finally
            {
                PortalNotes.Close();
            }
        }



        //protected void rlPortalNotes_RowUpdating(object sender, GridViewUpdateEventArgs e)
        //{
        //    PortalNotesBL PortalnotesUpdt = new PortalNotesBL();
        //    try
        //    {
        //        rlPortalNotes.Columns[1].Visible = true;
        //        rlPortalNotes.Columns[0].Visible = true;
        //        HiddenField hdnPortalNotesID = (HiddenField)rlPortalNotes.Rows[e.RowIndex].FindControl("hdnPortalNotesID");

        //        PortalnotesUpdt.PortalNotesid = Convert.ToInt32(hdnPortalNotesID.Value);
        //        PortalnotesUpdt.Title = ((TextBox)rlPortalNotes.Rows[e.RowIndex].FindControl("txtTitle")).Text;
        //        PortalnotesUpdt.Notes = ((TextBox)rlPortalNotes.Rows[e.RowIndex].FindControl("txtNotes")).Text;
        //        PortalnotesUpdt.Visiblestartdate = ((TextBox)rlPortalNotes.Rows[e.RowIndex].FindControl("txtVisibleStartDate")).Text;
        //        PortalnotesUpdt.Visibleenddate = ((TextBox)rlPortalNotes.Rows[e.RowIndex].FindControl("txtVisibleEndDate")).Text;

        //        CheckBoxList chkVisibleStaffID = (CheckBoxList)rlPortalNotes.Rows[e.RowIndex].FindControl("chkVisibleStaffID");
        //        string strvisibleto = "";
        //        foreach (ListItem cBox in chkVisibleStaffID.Items)
        //        {
        //            if (cBox.Selected)
        //            {
        //                strvisibleto += cBox.Value + " , ";
        //            }
        //        }
        //        PortalnotesUpdt.Visiblestaffid = strvisibleto;
        //        PortalnotesUpdt.UpdatePortalNotes();

        //        rlPortalNotes.EditIndex = -1;
        //        PopulatePortalNotesGrid();


        //    }
        //    catch
        //    {
        //    }
        //    finally
        //    {
        //        PortalnotesUpdt = null;
        //    }
        //}

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ResetFormControlValues(this.Page);
            chkVisibleUser.SelectedIndex = -1;
            txtNoteEditor.Text = "";
            PopulatePortalNotesGrid();
        }
        protected void btnEditCancle_Click(object sender, EventArgs e)
        {
            ResetFormControlValues(this.Page);
            chkVisibleUserEdit.SelectedIndex = -1;
            txtNoteEditorEdit.Text = "";
            PopulatePortalNotesGrid();
            ModalPopupExtenderEdit.Enabled = false;
        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            OpenSISWCFServicePortalNotesClient PortalnotesUpdt = new OpenSISWCFServicePortalNotesClient();
            try
            {
                int PortalNotesid = Convert.ToInt32(hdnportalnoteid.Value);
                string Title = txtTitleEdit.Text.Trim();
                string Notes = Server.HtmlEncode(hdnNoteEditor.Value.ToString());
                string Visiblestartdate = txtVisibleStartDateEdit.Text.ToString(DateTimeFormatInfo.InvariantInfo);
                string Visibleenddate = txtVisibleEndDateEdit.Text.ToString(DateTimeFormatInfo.InvariantInfo);

                string strvisibleto = "";
                foreach (ListItem cBox in chkVisibleUserEdit.Items)
                {
                    if (cBox.Selected)
                    {
                        strvisibleto += cBox.Value + " , ";
                    }
                }
                string Visiblestaffid = strvisibleto;



                PortalnotesUpdt.UpdatePortalNotes(Title,Notes,Visiblestartdate,Visibleenddate,Visiblestaffid,PortalNotesid);
                ResetFormControlValues(this.Page);
                chkVisibleUserEdit.SelectedIndex = -1;
                PopulatePortalNotesGrid();
                ModalPopupExtenderEdit.Enabled = false;

            }
            catch
            {
            }
            finally
            {
                PortalnotesUpdt.Close();
            }
        }


        public void PopulateStaffTypecheckbox(ref CheckBoxList chklist)
        {
            OpenSISWCFServicePortalNotesClient PNBL = new OpenSISWCFServicePortalNotesClient();
            DataTable dt = PNBL.PopulateStaffTypecheckbox();

            chklist.DataSource = dt;
            chklist.DataTextField = "stf_type_name";
            chklist.DataValueField = "stf_type_cd";
            chklist.DataBind();


            PNBL.Close();
        
        }

        public void PopulateSelectedStaffTypecheckbox(ref CheckBoxList chklist,string visiblestaffid)
        {
            OpenSISWCFServicePortalNotesClient PNBL = new OpenSISWCFServicePortalNotesClient();
            DataTable dt = PNBL.PopulateSelectedStaffTypecheckbox(visiblestaffid);

            chklist.DataSource = dt;
            chklist.DataTextField = "stf_type_name";
            chklist.DataValueField = "stf_type_cd";
            chklist.DataBind();


            PNBL.Close();
        
        }



        private void ml_InitCulture()
        {

            String MLCultureName = (String)Session["MLCulture"];
            String MLUICultureName = (String)Session["MLUICulture"];
            sCulture = Session["MLCulture"].ToString();
            if ((MLCultureName != null) && (MLCultureName.Length > 0))
            {
                Page.Culture = MLCultureName;
            }

            if ((MLUICultureName != null) && (MLUICultureName.Length > 0))
            {
                Page.UICulture = MLUICultureName;
            }
        }

        protected override void InitializeCulture()
        {
            ml_InitCulture();
        }
    }
}